<%@language=vbscript%>
<%
	Session("bChucnang")=10
	Session("FormName")="F19"
%>
<!--#include file="..\CheckSession.inc"-->
<!--#include file="..\RootContent.inc"-->
<!--#include file=..\getFormName.inc-->
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Y kien lanh dao</title>
</head>
<%	
	bComm=Request("bComm")
	bID=Request("bID")
	backform=request("backform")+1
	if bComm="update" then
		bykienxuly=Request("bykienxuly")
		bdonvixuly=Request("bdonvixuly")
		i=instr(1,bdonvixuly,",")
		bdonvixuly=mid(bdonvixuly,1,i-1)
		sSQL="delete YKXL_HXL where idvtden like '"& bID &"'"
		Conn.Execute sSQL
		Set RecKT=server.CreateObject("ADODB.Recordset")
		ssql= "select * from DonVi where madonvi like '00%00' and madonvi <> '000000' order by madonvi"
		RecKT.Open ssql,Conn
		do while not RecKT.EOF
			R="CheckR"&RecKT("madonvi")
			bCheckR=Request(R)
			T="TxtHXL"&RecKT("madonvi")
			bhanxuly=Request(T)
			if bCheckR<>"" and bhanxuly <> "" then
				if bdonvixuly="" then
					bdonvixuly=RecKT("tendonvi")
				else
					bdonvixuly=bdonvixuly+", "+RecKT("tendonvi")
				end if
				sSQL="insert into YKXL_HXL(idvtden,madonvi,hanxuly,nbdxuly,trangthai) values ('"& bID &"','"& RecKT("madonvi") &"','"& SaveDate(bhanxuly) &"','"& date() &"',1)"
				Conn.Execute sSQL
			end if
		RecKT.MoveNext
		loop
		RecKT.close
		set RecKT=nothing
		bmadonvi=Donvixuly(bdonvixuly)
		sSQL="Update vtden set ykienxuly='"& bykienxuly &"',noinhan='"& bdonvixuly &"',donvixuly='"& bmadonvi &"' Where ID Like '"& bID &"'"
		Conn.Execute sSQL
		sSQL="delete hoanthanhxl where idvtden = '"& bID &"' and madonvi= '"& Session("bMaDonVi") &"' and trangthai=0"
		Conn.Execute sSQL
		sSQl="insert into hoanthanhxl(idvtden,idvtdi,ngayhtxl,madonvi,kqxl,trangthai) values ('"& bID &"','','"& date() &"','"& Session("bMaDonVi") &"','',0)"
		Conn.Execute sSQL
		Set RecKT=server.CreateObject("ADODB.Recordset")
		ssql= "select ngaybatdau,thxl from vtden where id = '"& bID &"'"
		RecKT.CursorType=3
		RecKT.CacheSize=5
		RecKT.Open ssql,Conn
		if RecKT.recordcount then
			sSQL="insert into YKXL_HXL(idvtden,madonvi,hanxuly,nbdxuly,trangthai) values ('"& bID &"','"& Session("bMaDonVi") &"','"& RecKT("ngaybatdau") &"','"& RecKT("thxl") &"',0)"
			Conn.Execute sSQL
		end if
		RecKT.close
		set RecKT=nothing
	end if
	sSQL="Select * from VTDEN Where ID Like '"& bID &"'"
	Set RecT=Server.CreateObject("ADODB.Recordset")
	RecT.CursorType=3
	RecT.CacheSize=5
	RecT.Open sSQL,Conn
	if RecT.RecordCount>0 then
		bykienxuly=RecT("ykienxuly")
		bdonvixuly=RecT("noinhan")
	end if
	RecT.close
	Set RecT=Nothing
%>	
<!--#include file="..\jvfunction.inc"-->
<script language=vbscript runat=server>
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   if vDate<>"" then
		   vDate=trim(cstr(vDate))
		   bvitri1=instr(1,vDate,"/")
		   bMonth=left(vDate,bvitri1-1)
		   bvitri2=instr(bvitri1+1,vDate,"/")
		   Dim Temp
		   Temp=right(vDate,len(vDate)-bvitri1)
		   bDay=left(Temp,bvitri2-bvitri1-1)
		   bYear=right(vDate,len(vDate)-bvitri2)
		   SaveDate=bDay+"/"+bMonth+"/"+bYear
	   else
	       SaveDate=""
	   end if
	End Function
	Function FormatDate(vDate)
	   If vDate <> "" Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
		Else
			FormatDate=""
	   End If
	End Function
	Function ModiString(mess_s)
		message = Replace("" & mess_s,"'", "''")
		ModiString=message
	End function
Function Donvixuly(strTendonvixuly)
	check=true
	if strTendonvixuly="" then
		strdonvixuly=""
	else
		strdonvixuly="-"
	end if
	strdonvixulyloi=""
	intlong=len(strTendonvixuly)
	i=0
	i=instr(1,strTendonvixuly,",")
	j=1
	k=0
	l=0
	if i <=0 then
		c=0
		Set RecDV=server.CreateObject("ADODB.Recordset")
		RecDV.CursorType=3
		RecDV.CacheSize=5
		c=instr(1,strTendonvixuly,"LĐTC")
		if c=1 then
			CTendonvixuly="LĐTC"
		else
			CTendonvixuly=strTendonvixuly
		end if
		sSQL="select madonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
		RecDV.Open sSQL,Conn
		if RecDV.Recordcount then
			strdonvixuly="-"+RecDV("madonvi")+"M-"
		else
			strdonvixulyloi=strTendonvixuly
		end if
		RecDV.close
		set RecDV=nothing
	else
		do while check
			c=0
			Set RecDV=server.CreateObject("ADODB.Recordset")
			RecDV.CursorType=3
			RecDV.CacheSize=5
			c=instr(1,mid(strTendonvixuly,j,i-j),"LĐTC")
			if c=1 then
				CTendonvixuly="LĐTC"
			else
				CTendonvixuly=mid(strTendonvixuly,j,i-j)
			end if
			sSQL="select madonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
			RecDV.Open sSQL,Conn
			if RecDV.Recordcount then
				if l=0 then
					strdonvixuly=strdonvixuly+RecDV("madonvi")+"M-"
				else
					strdonvixuly=strdonvixuly+RecDV("madonvi")+"S-"
				end if
			else
				strdonvixulyloi=strdonvixulyloi+mid(strTendonvixuly,j,i-j)+","
			end if
			RecDV.close
			set RecDV=nothing
			k=instr(i+1,strTendonvixuly,",")
			j=i+2
			if k <=0 then
				c=0
				check=false
				Set RecDV=server.CreateObject("ADODB.Recordset")
				RecDV.CursorType=3
				RecDV.CacheSize=5
				c=instr(1,mid(strTendonvixuly,j,intlong-j+1),"LĐTC")
				if c=1 then
					CTendonvixuly="LĐTC"
				else
					CTendonvixuly=mid(strTendonvixuly,j,intlong-j+1)
				end if
				sSQL="select madonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
				RecDV.Open sSQL,Conn
				if RecDV.Recordcount then
					strdonvixuly=strdonvixuly+RecDV("madonvi")+"S-"
				else
					strdonvixulyloi=strdonvixulyloi+mid(strTendonvixuly,j,intlong-j+1)+","
				end if
				RecDV.close
				set RecDV=nothing
			else
				check=true
			end if
			i=k
			l=l+1
		loop
	end if
	Donvixuly=strdonvixuly
End function
Function TenDonvixuly(strTendonvixuly)
	check=true
	if strTendonvixuly="" then
		strdonvixuly=""
	else
		strdonvixuly=""
	end if
	strdonvixulyloi=""
	intlong=len(strTendonvixuly)
	i=0
	i=instr(1,strTendonvixuly,",")
	j=1
	k=0
	l=0
	if i <=0 then
		c=0
		Set RecDV=server.CreateObject("ADODB.Recordset")
		RecDV.CursorType=3
		RecDV.CacheSize=5
		c=instr(1,strTendonvixuly,"LĐTC")
		if c=1 then
			CTendonvixuly="LĐTC"
		else
			CTendonvixuly=strTendonvixuly
		end if
		sSQL="select tendonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
		RecDV.Open sSQL,Conn
		if RecDV.Recordcount then
			strdonvixuly=RecDV("tendonvi")
		else
			strdonvixulyloi=strTendonvixuly
		end if
		RecDV.close
		set RecDV=nothing
	else
		do while check
			c=0
			Set RecDV=server.CreateObject("ADODB.Recordset")
			RecDV.CursorType=3
			RecDV.CacheSize=5
			c=instr(1,mid(strTendonvixuly,j,i-j),"LĐTC")
			if c=1 then
				CTendonvixuly="LĐTC"
			else
				CTendonvixuly=mid(strTendonvixuly,j,i-j)
			end if
			sSQL="select tendonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
			RecDV.Open sSQL,Conn
			if RecDV.Recordcount then
				if l=0 then
					if strdonvixuly="" then
						strdonvixuly=RecDV("tendonvi")
					else
						strdonvixuly=strdonvixuly+RecDV("tendonvi")
					end if
				else
					if strdonvixuly="" then
						strdonvixuly=RecDV("tendonvi")
					else
						strdonvixuly=strdonvixuly+", "+RecDV("tendonvi")
					end if
				end if
			else
				strdonvixulyloi=strdonvixulyloi+mid(strTendonvixuly,j,i-j)+","
			end if
			RecDV.close
			set RecDV=nothing
			k=instr(i+1,strTendonvixuly,",")
			j=i+2
			if k <=0 then
				c=0
				check=false
				Set RecDV=server.CreateObject("ADODB.Recordset")
				RecDV.CursorType=3
				RecDV.CacheSize=5
				c=instr(1,mid(strTendonvixuly,j,intlong-j+1),"LĐTC")
				if c=1 then
					CTendonvixuly="LĐTC"
				else
					CTendonvixuly=mid(strTendonvixuly,j,intlong-j+1)
				end if
				sSQL="select tendonvi from donvi where tendonvi like '"& CTendonvixuly &"'"
				RecDV.Open sSQL,Conn
				if RecDV.Recordcount then
					if strdonvixuly="" then
						strdonvixuly=RecDV("tendonvi")
					else
						strdonvixuly=strdonvixuly+", "+RecDV("tendonvi")
					end if
				else
					strdonvixulyloi=strdonvixulyloi+mid(strTendonvixuly,j,intlong-j+1)+","
				end if
				RecDV.close
				set RecDV=nothing
			else
				check=true
			end if
			i=k
			l=l+1
		loop
	end if
	TenDonvixuly=strdonvixuly
End function
</script>	
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--
function CmdOK_onclick() {
		ykienxuly=Noidung.TxtYkienxuly.value;
		window.Noidung.target="right"
		window.Noidung.action="frmYkienxuly.asp?bID="+"<%=bID%>"+"&backform="+"<%=backform%>"+"&bComm=update&bykienxuly="+ykienxuly+"&bdonvixuly="+"<%=bdonvixuly%>";
		window.Noidung.submit()
}
function CmdExit_onclick(){
	window.Noidung.target="right";
	window.Noidung.action="<%=Session("tenvtden")%>";
	window.Noidung.submit();
}
//-->
</SCRIPT>
<%
response.write("<SCRIPT LANGUAGE=javascript>")
	Set RecDV=server.CreateObject("ADODB.Recordset")
	ssql= "select * from DonVi where madonvi like '00%00' and madonvi <> '000000' order by madonvi"
	RecDV.Open ssql,Conn
	do while not RecDV.EOF
		response.write("function CheckR"&RecDV("madonvi")&"_onclick(){")
		response.write("if ( Noidung.CheckR"&RecDV("madonvi")&".checked ) {")
		response.write("Noidung.TxtHXL"&RecDV("madonvi")&".disabled=false;")
		response.write("Noidung.TxtHXL"&RecDV("madonvi")&".focus();")
		response.write("}")
		response.write("else")
		response.write("{")
		response.write("Noidung.TxtHXL"&RecDV("madonvi")&".value='';")
		response.write("Noidung.TxtHXL"&RecDV("madonvi")&".disabled=true;")
		response.write("}")
		response.write("}")
		response.write("function TxtHXL"&RecDV("madonvi")&"_onkeyup(str){")
		response.write("var keycode;")
		response.write("keycode=window.event.keyCode;")
		response.write("if (isEdit(keycode,str)){")
		response.write("Noidung.TxtHXL"&RecDV("madonvi")&".value=editdate(trim(str));")
		response.write("}")
		response.write("}")
	RecDV.MoveNext
	loop
	RecDV.close
	set RecDV=nothing
response.write("</SCRIPT>")
%>
<body bgcolor=#F8F9D9 topmargin="0" leftmargin="0" style="font-family:times new roman">
<%if Msg<>"" then%>
	<p align=center><font color=red><%=Msg%></p>
<%end if%>	
<form name=Noidung method=post>
<table border="0" cellspacing="0" style="font-size:12pt" width="100%" bgcolor="#F8F9D9">
<tr>
    <td width="100%" colspan="2" bgcolor="#000080">
    <p align="center"><font color="#FFFFFF"><span style="font-size: 11pt"><b>Ý KIẾN LÃNH ĐẠO</b></span></font></td>
</tr>
<!-- 	 -->
<tr>
    <td width="17%" valign=top>Ý kiến lãnh đạo</TD>
	<td width="83%"><textarea name=TxtYkienxuly maxLength=500 style='font-family:Arial; width:100%' rows=4 cols=82 tabindex=3><%=bykienxuly%></textarea></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="4" style="font-size:13pt" bgcolor="#F8F9D9">
</tr>
	<td width="35%"></td>
	<td width="15%"><Button name="CmdOK" style="font-family:Arial;width: 100%"  LANGUAGE=javascript onclick="return CmdOK_onclick()" accesskey="G" tabindex=4><p><u>G</u>hi nhận</p></Button></td>
	<td width="15%"><Button name="CmdExit" style="font-family: Arial;width: 100%" LANGUAGE=javascript onclick="return CmdExit_onclick()" accesskey="Y" tabindex=5><p>Qua<u>y</u> lại</p></Button></td>
	<td width="35%"></td>
</tr>
</Table>
<table border="0" width="100%" style="font-size:13;font-family:arial;border-style: solid;border-color:#C0C0C0">
	<tr bgcolor="#bdd5d0">
	<td width="5%" ></td>
	<td width="65%" align="left">Đơn vị xử lý</td>
	<td width="25%" align="center">Thời hạn xử lý</td>
	</tr>
<%
	Set RecDonvi=server.CreateObject("ADODB.Recordset")
	sSQL="select DonVi.*,ykxl_hxl.hanxuly from DonVi left outer join ykxl_hxl on DonVi.madonvi=ykxl_hxl.madonvi and ykxl_hxl.idvtden = '"& bID &"' and ykxl_hxl.trangthai=1  where DonVi.madonvi like '00%00' and DonVi.madonvi <> '000000' and DonVi.madonvi <> '"& Session("bMaDonVi") &"' order by DonVi.madonvi"
	RecDonvi.Open ssql,Conn
	cnt=1
	do while not RecDonvi.EOF
		if (cnt/2=int(cnt/2)) then
			color="#eeeecc"
		else
			color="#F8F9D9"
		end if
%>
	<tr bgcolor=<%=color%>>
	<% if RecDonvi("hanxuly") then%>
		<td width="5%" align="center"><input type="checkbox" name=CheckR<%=RecDonvi("madonvi")%> value="ON" checked LANGUAGE=javascript onclick="return CheckR<%=RecDonvi("madonvi")%>_onclick()"></td>
	<%else%>
		<td width="5%" align="center"><input type="checkbox" name=CheckR<%=RecDonvi("madonvi")%> value="ON" LANGUAGE=javascript onclick="return CheckR<%=RecDonvi("madonvi")%>_onclick()"></td>
	<%end if%>
	<td width="70%" align="left"><%=RecDonvi("tendonvi")%></td>
	<% if RecDonvi("hanxuly") then%>
		<td width="25%" align="left"><input name='TxtHXL<%=RecDonvi("madonvi")%>' value=<%=FormatDate(RecDonvi("hanxuly"))%> maxlength=12 style='font-family:Arial; width:100%' size="12" LANGUAGE=javascript onkeyup="return TxtHXL<%=RecDonvi("madonvi")%>_onkeyup(this.value)"></td>
	<%else%>
		<td width="25%" align="left"><input name='TxtHXL<%=RecDonvi("madonvi")%>' disabled maxlength=12 style='font-family:Arial; width:100%' size="12" LANGUAGE=javascript onkeyup="return TxtHXL<%=RecDonvi("madonvi")%>_onkeyup(this.value)"></td>
	<%end if%>
	</tr>
<%
	RecDonvi.MoveNext
	cnt=cnt+1
	loop
	RecDonvi.close
	set RecDonvi=nothing
	%>
</table>
</form>
</font>
</body>
</html>
<%
	Conn.Close
	set Conn=nothing
%>